import type { App } from 'vue'
import FxLogger from '@/js/fxLogger'
import vuex from '@/store'
import { getFxLoggerRemote } from '@/config/env.config'

const LOGGER_CONFIG = {
	release: {
		app: 'scm8-production',
		remote: 'https://mobile.engine.fxscm.net/logger/v1/scm8-production/loggers'
	},
	development: {
		app: 'scm8-dev',
		remote: 'http://action.fxscm.net/logger/v1/scm8-dev/loggers'
	}
}
const LOGGER_DEFAULT_INFO = {
	platformType: 'PAD'
}
const LOGGER_CUSTOM_INFO = {
	billType: 0
}
const creatLoggerConfig = function () {
	return {
		...LOGGER_CONFIG[getFxLoggerRemote()],
		defaultInfo: LOGGER_DEFAULT_INFO,
		customInfo: LOGGER_CUSTOM_INFO
	}
}
const install = (app: App): void => {
	const fxLogger = new FxLogger(creatLoggerConfig(), app)
	app.config.globalProperties.$fxLogger = fxLogger
	const user = {
		username: vuex.getters.usernameGetter,
		tenantId: vuex.getters.getTenantId,
		employeeName: vuex.getters.getEmployeeName,
		organName: vuex.getters.getOrganName,
		userId: vuex.getters.getUserId,
		hostId: vuex.getters.getHostId
	}
	fxLogger.init(user)
}

export default {
	install,
	FxLogger
}
